#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * DNS T-Key Record Structure
 *      Represents a DNS T-key (TKEY) record.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
using namespace System;
using namespace System::Net;

namespace Adaptive
{
	namespace Network
	{
		namespace Dns
		{
			/// <summary>
			/// Represents a DNS T-key (TKEY) record.
			/// </summary>
			public value struct DnsTKeyRecord
			{
			internal:
				/// <summary>
				/// Initializes a new instance of the class from the unmanaged record.
				/// </summary>
				/// <param name="record"> A pointer to a DNS_RECORD structure whose contents are to be copied.</param>
				DnsTKeyRecord(DNS_RECORD* record)
				{
					if ((record == NULL) || (record->wType != DNS_TYPE_TKEY))
					{
						AlgorithmName = String::Empty;
						AlgorithmPacket = IntPtr::Zero;
						KeyPointer = IntPtr::Zero;
						CreateTime = 0;
						ExpirationTime = 0;
						Mode = 0;
						Error = 0;
						KeyLength = 0;
						AlgorithmNameLength = 0;
					}
					else
					{
						AlgorithmName = gcnew String( record->Data.TKEY.pNameAlgorithm);
						AlgorithmPacket = IntPtr::IntPtr(record->Data.TKEY.pAlgorithmPacket);
						KeyPointer = IntPtr::IntPtr(record->Data.TKEY.pKey);
						CreateTime = record->Data.TKEY.dwCreateTime;
						ExpirationTime = record->Data.TKEY.dwExpireTime;
						Mode = record->Data.TKEY.wMode;
						Error = record->Data.TKEY.wError;
						KeyLength = record->Data.TKEY.wKeyLength;
						AlgorithmNameLength = record->Data.TKEY.cAlgNameLength;
					}
				}
			private:
				/// <summary>
				/// Static constructor.
				/// </summary>
				static DnsTKeyRecord()
				{
				}
			public:

				/// <summary>
				/// A string representing the name of the algorithm used with the key.
				/// </summary>
				/// <value>
				/// An algorithm name string, or an empty string.
				/// </value>
				String^		AlgorithmName;
				/// <summary>
				/// Pointer to the packet containing the algorithm.
				/// </summary>
				/// <value>
				/// An <see cref="IntPtr"/> containing the pointer data, or <b>IntPtr.Zero</b>.
				/// </value>
				IntPtr		AlgorithmPacket;
				/// <summary>
				/// Pointer to the key.
				/// </summary>
				/// <value>
				/// An <see cref="IntPtr"/> containing the pointer data, or <b>IntPtr.Zero</b>.
				/// </value>
				IntPtr		KeyPointer;
				/// <summary>
				/// Date and time at which the key was created, expressed in seconds since the beginning of January 1, 1970, 
				/// Greenwich Mean Time (GMT), excluding leap seconds.
				/// </summary>
				/// <value>
				/// Creation time for the key, in seconds.
				/// </value>
				int			CreateTime;
				/// <summary>
				/// Expiration date of the key, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean 
				/// Time (GMT), excluding leap seconds.
				/// </summary>
				/// <value>
				/// Expiration time for the key, in seconds.
				/// </value>
				int			ExpirationTime;
				/// <summary>
				/// Scheme used for key agreement or the purpose of the TKEY DNS Message.
				/// </summary>
				/// <value>
				/// DNS agreement mode value.
				/// </value>
				short		Mode;
				/// <summary>
				/// Error, expressed in expanded RCODE that covers TSIG processing and TKEY processing.
				/// </summary>
				/// <value>
				/// An RCODE value.
				/// </value>
				short		Error;
				/// <summary>
				/// Length, in bytes, of the signature member.
				/// </summary>
				/// <value>
				/// Size of the related signature.
				/// </value>
				short		KeyLength;
				/// <summary>
				/// Length, in bytes, of the AlgorithmName member
				/// </summary>
				/// <value>
				/// Size of the algorithm name.
				/// </value>
				Byte		AlgorithmNameLength;
			};
		}
	}
}